<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
      <template #operationBeforeExtend="{ record }">
        <a-link @click="openAdvList(record)">
          <icon-menu/>
          广告管理
        </a-link>
      </template>

      <template #up_img="{ record }">
        <a-avatar>
          <img :src="record.up_img" style="object-fit: cover" />
        </a-avatar>
      </template>
    </ma-crud>

    <adv-list ref="advListRef"/>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import infoAdvPosition from '@/api/info/infoAdvPosition'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
import advList from './components/adv.vue'

const crudRef = ref()


const advListRef = ref()
const openAdvList = (row) => {
  advListRef.value.open(row);
}

const numberOperation = (newValue, id, numberName) => {
  infoAdvPosition.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  infoAdvPosition.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'us_info_adv_position',
  rowSelection: {
    showCheckedAll: true
  },
  bordered:{ wrapper: true, cell: true },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 220,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: infoAdvPosition.getList,
  recycleApi: infoAdvPosition.getRecycleList,
  add: {
    show: true,
    api: infoAdvPosition.save,
    auth: ['info:advPosition:save']
  },
  edit: {
    show: true,
    api: infoAdvPosition.update,
    auth: ['info:advPosition:update']
  },
  delete: {
    show: true,
    api: infoAdvPosition.deletes,
    auth: ['info:advPosition:delete'],
    realApi: infoAdvPosition.realDeletes,
    realAuth: ['info:advPosition:realDeletes']
  },
  recovery: {
    show: true,
    api: infoAdvPosition.recoverys,
    auth: ['info:advPosition:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    width:80,
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "位置名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "位置Key",
    dataIndex: "key",
    formType: "input",
    search: true
  },
  {
    title: "占位图",
    dataIndex: "up_img",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "描述",
    dataIndex: "summary",
    formType: "textarea",
    hide:true
  },
  {
    title: "会员购买",
    dataIndex: "is_allow",
    formType: "radio",
    dict: {
      data: [
        {
          label: "未审核",
          value: "0"
        },
        {
          label: "审核已通过",
          value: "1"
        },
        {
          label: "审核未通过",
          value: "2"
        }
      ],
      translation: true
    },
    addDefaultValue: '1',
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    dict: {
      name: "data_show_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    addDefaultValue: '1',
    search: true
  },
  {
    title: "创建时间",
    width:180,
    dataIndex: "create_time",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'info:advPosition' } </script>